package second.thread.threecore;

import java.util.concurrent.CyclicBarrier;

/**
 * @Author: heweiwei
 * @Date: 2/8/25 PM4:16
 * @Description:
 */
public class SimpleCyclicBarrierExample {

    public static void main(String[] args) {


        // 创建 CyclicBarrier 实例，指定运动员数量和所有运动员到达屏障点后要执行的操作
        CyclicBarrier barrier = new CyclicBarrier(3, () -> System.out.println("所有运动员已准备好，比赛开始！"));
        // 创建并启动运动员线程
        String[] athleteNames = {"张三", "李四", "王五"};
        for (String name : athleteNames) {
            new Thread(new Athlete(barrier, name)).start();
        }
    }
}
